﻿#ifndef ABSTRACT_KEYBOARD_H
#define ABSTRACT_KEYBOARD_H

#include <QApplication>
#include <QKeyEvent>
#include <QString>
#include <QWidget>


class AbstractKeyBoard : public QWidget
{
    Q_OBJECT
public:
    AbstractKeyBoard(QWidget *parent = 0) : QWidget(parent) {

    }
    ~AbstractKeyBoard() { }

    QWidget *getReceiver() const
    {
        return m_receiver;
    }

    void setReceiver(QWidget *value)
    {
        m_receiver = value;
    }

public slots:
    virtual void update(const QString &text) { Q_UNUSED(text); }

    void onKeyPressed(int key, QString value)
    {
        if (!m_receiver)
            return;

        QKeyEvent keyPress(QEvent::KeyPress,     key, Qt::NoModifier, value);
        QKeyEvent keyRelease(QEvent::KeyRelease, key, Qt::NoModifier, value);

        QApplication::sendEvent(m_receiver, &keyPress);
        QApplication::sendEvent(m_receiver, &keyRelease);
    }

signals:
    void keyPressed(int key, QString value);

private:
	QWidget *m_receiver{ nullptr };
};

#endif // ABSTRACT_KEYBOARD_H
